package jNotesGUI;

import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Map;

import javax.swing.InputMap;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import jNotesGUI.TextLocalization;

public final class Menu
{
	MenuListener fListen;
	
	ArrayList<String> MenuText = new ArrayList<String>(); 
	
	JMenu File;
	JMenuItem New;
	JMenuItem Open;
	JMenuItem Save;
	JMenuItem Backup;
	JMenuItem Exit;
	
	JMenu Edit;
	JMenuItem Cut;
	JMenuItem Copy;
	JMenuItem Paste;
	JMenuItem SelectAll;
	JMenuItem Delete;
	JMenuItem Preferences;
	
	JMenu Help;
	JMenuItem _Help;
	JMenuItem About;
	
	String Locale;
	
	public Menu()
	{
		
		Locale = TextLocalization.locale;
		TextLocalization a = new TextLocalization();
		a.setLocale("es_ES");
		Map<String, ArrayList<String>> menuMap = a.getLocaleMap();
		
		ArrayList<String> menuString = menuMap.get("Menu");
		
		fListen = new MenuListener(menuString);
		
		File = new JMenu(menuString.get(0));
		File.add(New = makeMenuItem(menuString.get(1)));
		File.add(Open = makeMenuItem(menuString.get(2)));
		File.add(Save = makeMenuItem(menuString.get(3)));
		File.add(Backup = makeMenuItem(menuString.get(4)));
		File.add(Exit = makeMenuItem(menuString.get(5)));
		
		Edit = new JMenu(menuString.get(6));
		Edit.add(Cut = makeMenuItem(menuString.get(7)));
		Edit.add(Copy = makeMenuItem(menuString.get(8)));
		Edit.add(Cut = makeMenuItem(menuString.get(9)));
		Edit.add(SelectAll = makeMenuItem(menuString.get(10)));
		Edit.add(Delete = makeMenuItem(menuString.get(11)));
		Edit.add(Preferences = makeMenuItem(menuString.get(12)));
		
		Help = new JMenu(menuString.get(13));
		Help.add(_Help = makeMenuItem(menuString.get(14)));
		Help.add(About = makeMenuItem(menuString.get(15)));
		
		
		makeKeyBindings();
	}
	
	private void makeKeyBindings() 
	{
		//File_InsertNote_inputMap = File_InsertNote.getInputMap(JMenuBar.WHEN_IN_FOCUSED_WINDOW);
		//KeyStroke Ins = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0);
		//File_InsertNote_inputMap.put(Ins, "Ins");
		
		//File_InsertNote.getActionMap().put("Ins", new KeyStrokeListener(File_InsertNote));
		
		InputMap ExitInputMap;
		ExitInputMap = Exit.getInputMap(JMenuBar.WHEN_IN_FOCUSED_WINDOW);
		KeyStroke Ctr_Q = KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK );
		ExitInputMap.put(Ctr_Q, "Ctr + Q");
		
		Exit.getActionMap().put("Ctr + Q", new KeyStrokeListener(Exit));
	}

	private JMenuItem makeMenuItem(final String name)
	{
		JMenuItem m = new JMenuItem(name);
		m.addActionListener(fListen);
		return m;
	}
	
	public void sendMain(Main a)
	{
		if(a!=null)
			fListen.window = a;
		else
			System.out.println("a is null!!!");
	}
}
